package top.kaoshanji.p3ch17b;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.HandlesTypes;
import java.util.Set;

/**
 * 代码清单-p3ch17b-292页b：ServletContainerInitializer实现类
 * 需要基于SPI机制配置
 * @author kaoshanji
 * ^_^
 * create time 2025/4/9 17:07
 */
@HandlesTypes({UsefulServlet.class})
public class MyServletContainerInitializer implements ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
        System.out.println("onStartup");

        ServletRegistration registration = ctx.addServlet("usefulServlet", "top.kaoshanji.p3ch17b.UsefulServlet");
        registration.addMapping("/useful");

        System.out.println("leaving onStartup");
    }

}
